from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text, JSON
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database import Base


class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    email = Column(String(255), unique=True, index=True, nullable=False)
    username = Column(String(50), unique=True, index=True, nullable=False)
    hashed_password = Column(String(255), nullable=False)
    
    # 基本信息
    full_name = Column(String(100))
    avatar_url = Column(String(500))
    bio = Column(Text)
    location = Column(String(100))
    website = Column(String(200))
    
    # 技能和标签
    skills = Column(JSON, default=list)  # ["Python", "Machine Learning", ...]
    interests = Column(JSON, default=list)  # ["AI", "Web Development", ...]
    
    # 状态和权限
    is_active = Column(Boolean, default=True)
    is_verified = Column(Boolean, default=False)
    is_admin = Column(Boolean, default=False)
    
    # 统计数据
    competitions_joined = Column(Integer, default=0)
    projects_created = Column(Integer, default=0)
    teams_joined = Column(Integer, default=0)
    reputation_score = Column(Integer, default=0)
    
    # 时间戳
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())
    last_login = Column(DateTime(timezone=True))
    
    # 关系
    teams = relationship("TeamMember", back_populates="user")
    projects = relationship("Project", back_populates="creator")
    notifications = relationship("Notification", back_populates="user")